#!/usr/local/bin/python2.7
# encoding: utf-8
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QColor, QBrush, QPen, QPainter
from PyQt4.QtCore import Qt
'''
codes couleur :
    - (rouge,vert,bleu,opacité) les 4 valeurs sont des entiers dans [0,255], 
    - "#rrvvbbtt" r,v,b et t sont dans {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}
'''
SCALE = 1.0
class NPrefs():
#     basecolor  = QColor(200,200,200)
#     
#     PEN   = QPen(basecolor.darker(), 0)
#     BRUSH = QBrush(basecolor)
#     toto = 'est content'
#     SELECTED_PEN    = QPen(basecolor, 0)
#     SELECTED_BRUSH  = QBrush(basecolor.lighter())
    def __str__(self):
        s0 = '<'+self.__class__.__name__+'>' 
        if self.__class__.__doc__ is not None : 
            s0 = s0 + ' '+str(self.__class__.__doc__)
        s = [s0]
        for key, value in sorted(self.__class__.__dict__.iteritems()) : 
            if str(value).find('__')>=0 or key == '__doc__' or key == '__module__':continue
            if isinstance(value, QColor) : 
                svalue = str(value.getRgb())
#                 svalue = str(value.name())
            elif isinstance(value, (QBrush,QPen,)):
#                 svalue = str(value.color().name())
                svalue = str(value.color().getRgb())
            else : 
                svalue = str(value)
            s.append(str(key)+' : '+svalue)
        return '\n   '.join(s)

class ViewPrefs(NPrefs) : 
#View
    base = QColor(250, 0, 0, 50)
    BACKGROUND_PEN = QPen(Qt.red,0)
    FOREGROUND_PEN = QPen(base.lighter(),0)
    BACKGROUND_BRUSH = QBrush(Qt.white)#QBrush(QColor(0, 0, 255, 10))
    FOREGROUND_BRUSH = QBrush(QColor(0, 0, 0, 0))#dernier chiffre=opacite
    AXES_PEN = QPen(base.darker(300),0)
class ScenePrefs(NPrefs) :
#SCENE
    BACKGROUND_BRUSH = QBrush(Qt.white)#QBrush(QColor(233,233,233))
    FOREGROUND_BRUSH = QBrush(QColor(0, 0, 0, 50))#10))
    RECT_PEN = QPen(Qt.lightGray,0)#(QColor(100, 100, 100),0)
    RECT_PEN.setWidth(0)
    RECT_PEN.setCosmetic(False)#True)
#AXES
    AXES_PEN   = QPen(QColor("#aaaaaa"), 0)
#VOILE PLANE
    VP_BACKGROUND_BRUSH = QBrush(Qt.white)
    VP_FOREGROUND_BRUSH = QBrush(QColor(0, 0, 0, 0))# jouer sur opacité du fond avec 4e paramètre
    VP_RECT_PEN = QPen(Qt.white,0)
    VP_RECT_PEN.setWidth(0)
    VP_RECT_PEN.setCosmetic(False)
#VOUTE
    V_BACKGROUND_BRUSH = QBrush(Qt.white)
    V_FOREGROUND_BRUSH = QBrush(QColor(0, 0, 0, 0))
    V_RECT_PEN = QPen(Qt.white,0)
    V_RECT_PEN.setWidth(0)
    V_RECT_PEN.setCosmetic(False)
###################################################    
##############   Noeuds   #########################    
###################################################    
class NodePrefs(NPrefs) :
    """Noeuds ordinaires"""
    SIZE   = 3#pixels
    RECT   = QtCore.QRect(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    RECTF  = QtCore.QRectF(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    
    SHAPE  = QPainter.drawEllipse
    SELECTED_SHAPE  = QPainter.drawRect
    basecolor = QColor(255,100,100)
    PEN    = QPen(basecolor.darker(), 0)
    BRUSH  = QBrush(basecolor)
    
    SELECTED_PEN    = QPen(basecolor, 0)
    SELECTED_BRUSH  = QBrush(basecolor.lighter())
#    HOVER_SHAPE  = QPainter.drawEllipse
#    FOCUS_SHAPE  = QPainter.drawEllipse

class PhantomNodePrefs(NPrefs):
    SIZE   = 4#pixels
#     RECT   = QtCore.QRect(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    RECTF  = QtCore.QRectF(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    SHAPE  = QPainter.drawEllipse
    SELECTED_SHAPE  = QPainter.drawRect
    
    basecolor = QColor(100, 100, 100, 100)
    PEN    = QPen(basecolor.darker(), 0)
    BRUSH  = QBrush(basecolor)
    selectable = True
    movable = False
    
    selected = QColor(250, 100, 100, 100)
    SELECTED_PEN    = QPen(selected.darker())
    SELECTED_BRUSH  = QBrush(selected.lighter())

class ReperePrefs(NPrefs):
    SIZE   = 4#pixels
    RECT   = QtCore.QRect(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    RECTF  = QtCore.QRectF(-SIZE, -SIZE, 2*SIZE , 2*SIZE)
    SHAPE  = QPainter.drawEllipse
    SELECTED_SHAPE  = QPainter.drawRect
    
    basecolor = QColor(200, 100, 100, 200)
    PEN    = QPen(basecolor.darker(), 0)
    BRUSH  = QBrush(basecolor)
    
    selected = QColor(200, 100, 100)
    SELECTED_PEN    = QPen(selected, 3*SIZE)
    SELECTED_BRUSH  = QBrush(selected)
#############################################################
#############  profils, cloisons, shapes ####################
#############################################################
class PolyLinePrefs(NPrefs):
#    basecolor = QColor(QtCore.Qt.transparent)
    BRUSH = QBrush(QtCore.Qt.transparent)
    basecolor = QColor(110,110, 110, 110)
    SELECTED_BRUSH = QBrush(basecolor.lighter())
    SELECTED_PEN = QPen(basecolor.darker().darker().darker())
    PEN = QPen(basecolor.darker().darker())
    
class PolygonPrefs(NPrefs) : 
    #Hexagone
    forme = [(1./30,0), 
             (0.30901699437494745/30, 0.9510565162951535/30),
             (-0.8090169943749475/30, 0.587785252292473/30),
             (-0.8090169943749475/30, -0.587785252292473/30),
             (0.3090169943749473/30, -0.9510565162951536/30),
             ]
    points = [(SCALE*p[0], SCALE*p[1]) for p in forme]
    basecolor  = QColor(QColor(0,200,0, 100))
    PEN   = QPen(basecolor.darker(), 0)
    BRUSH = QBrush(basecolor)
    SELECTED_PEN   = QPen(basecolor, 0)
    SELECTED_BRUSH = QBrush(basecolor.darker().darker())
    
class ProfilPrefs(NPrefs) : 
    basecolor  = QColor(170,195,242, 100)

#     nbplissage = 50, 100 #intrados, extrados
#     tension = 5
    DX_MOVE, DY_MOVE = 0.1, 0.1
    DX_SCALE, DY_SCALE = 0.05, 0.05
    PEN   = QPen(basecolor.darker().darker().darker().darker(), 0)
    BRUSH = QBrush(basecolor)

    SELECTED_PEN   = QPen(basecolor, 0)
    SELECTED_BRUSH = QBrush(basecolor.darker().darker())
#    SELECTED_BRUSH = QBrush(QColor(255, 255, 255,100))
    
    splinecolor = QColor(250, 0, 0, 10)
    SPLINE_BRUSH = QBrush(splinecolor.lighter())
    
    splinecolor.setAlpha(255)
    SPLINE_PEN   = QPen(splinecolor.darker(), 0, QtCore.Qt.DashLine)
    SPLINE_PEN.setCosmetic(True)#??????
    SPLINE_PEN.setDashOffset(6)#??????
    SPLINE_FOLLOW_NODES = True#mise a jour auto de la spline APRES chaque déplacement de noeud (mais pas PENDANT)

# class CloisonPrefs(NPrefs):
#     VALID_SHAPES = ['trou', 'renfort', 'repere', 'jonc', 'autres', 'raccord']
#     basecolor = ProfilPrefs.basecolor
#     bgcolor = basecolor.lighter().lighter()
#     BG_PEN   = QPen(basecolor.darker().darker(), 0)
#     BG_BRUSH = QBrush(basecolor)
#     PEN   = QPen(basecolor.darker().darker().darker().darker(), 0)
#     BRUSH = QBrush(basecolor)
# 
#     SELECTED_PEN   = QPen(basecolor, 0)
#     SELECTED_BRUSH = QBrush(basecolor.darker().darker())
#     
# class CloisonDiagonalePrefs(NPrefs):
#     VALID_SHAPES = ['trou', 'renfort', 'repere', 'jonc', 'autres', 'raccord']
#     basecolor = CloisonPrefs.basecolor
#     bgcolor = basecolor.lighter().lighter()
#     BG_PEN   = QPen(basecolor.darker().darker(), 0)
#     BG_BRUSH = QBrush(basecolor)
#     
# class JoncPrefs(NPrefs):
#     "Rouge"
#     basecolor = QColor(255, 10, 10, 100)
#     bgcolor = basecolor.lighter().lighter()
#     BG_PEN   = QPen(basecolor.darker().darker(), 0)
#     BG_BRUSH = QBrush(basecolor)
#     BRUSH = QBrush(QtCore.Qt.transparent)
#     PEN = QPen(basecolor.darker().darker())
#     SELECTED_BRUSH = QBrush(basecolor.lighter())
#     SELECTED_PEN = QPen(basecolor.darker().darker().darker())
#     
# class RaccordPrefs(NPrefs):
#     '''Vert'''
#     basecolor = QColor(10, 200, 10, 100)
#     BRUSH = QBrush(QtCore.Qt.transparent)
#     PEN = QPen(basecolor.darker().darker())
#     SELECTED_BRUSH = QBrush(basecolor.lighter())
#     SELECTED_PEN = QPen(basecolor.darker().darker().darker())
#     bgcolor = basecolor.lighter().lighter()
#     BG_PEN   = QPen(basecolor.darker().darker(), 0)
#     BG_BRUSH = QBrush(basecolor)
#     
# class RenfortPrefs(NPrefs):
#     '''bleu'''
#     basecolor = QColor(10, 10, 200, 100)
#     BRUSH = QBrush(basecolor)
#     PEN = QPen(basecolor.darker().darker())
#     SELECTED_BRUSH = QBrush(basecolor.lighter())
#     SELECTED_PEN = QPen(basecolor.darker().darker().darker())
#     bgcolor = basecolor.lighter().lighter()
#     BG_PEN   = QPen(basecolor.darker().darker(), 0)
#     BG_BRUSH = QBrush(basecolor)
#     

if __name__ == "__main__" :
    for p in (TrouPrefs(), RenfortPrefs(), JoncPrefs(), AncrageNodePrefs()):
        print '******'
        print p
    
#     p = ProfilPrefs()
#     print '******'
#     print p
#     p = ControlNodePrefs()
#     print '******'
#     print p
#     p = Parametres()
#     print '******'
#     print p
#    print p.X0, p.basecolor


    
